# encoding: utf-8

import urllib

def main(env):
	mapTypes = dict(zip(env["static"]["cwMap_typeLocalNames"].split(", "),env["static"]["cwMap_typeNames"].split(", ")))
	queryDict = {
		"center": env["context"]["selection"].encode("utf8"), # BUG: with non-ascii characters, e.g. cwcarte(=besançon)
		"maptype": mapTypes[env["meta"]["richSuffix"].lower() if env["meta"]["richSuffix"] else env["prefs"]["cwMap_defaultType"]],
		"zoom": env["meta"]["antefix"] if env["meta"]["antefix"] else env["prefs"]["cwMap_defaultZoom"],
		"size": env["static"]["cwMap_size"],
		"sensor": "false",
		"format": "JPEG"
	}
	return [
		("htmlBox",{
			"url": 'https://maps.googleapis.com/maps/api/staticmap?%s' % urllib.urlencode(queryDict),
			"width": 640,
			"height": 640,
			"label": env["static"]["cwMap_label"]
		}),
		("moveCursor",0)
	]

